//
//  String+Extension.swift
//  CMDB
//
//  Created by 曹桂祥 on 17/4/10.
//  Copyright © 2017年 CMDB. All rights reserved.
//

import UIKit

extension String {
    
    internal func suitToSize(size: CGSize,fontSize: CGFloat ,lineSpacing: CGFloat) -> CGSize {
        let style = NSMutableParagraphStyle()
        
        style.lineSpacing = lineSpacing
        
        return self.boundingRectWithSize(size, options: NSStringDrawingOptions(rawValue: NSStringDrawingOptions.UsesLineFragmentOrigin.rawValue | NSStringDrawingOptions.UsesFontLeading.rawValue), attributes: [
            NSFontAttributeName :UIFont.systemFontOfSize(fontSize),
            NSParagraphStyleAttributeName : style
            ], context: nil).size
    }
    
    internal func suitToSize(size: CGSize,boldFontSize: CGFloat ,lineSpacing: CGFloat) -> CGSize {
        let style = NSMutableParagraphStyle()
        
        style.lineSpacing = lineSpacing
        
        return self.boundingRectWithSize(size, options: NSStringDrawingOptions(rawValue: NSStringDrawingOptions.UsesLineFragmentOrigin.rawValue | NSStringDrawingOptions.UsesFontLeading.rawValue), attributes: [
            NSFontAttributeName :UIFont.boldSystemFontOfSize(boldFontSize),
            NSParagraphStyleAttributeName : style
            ], context: nil).size
    }
    
}

extension String{
    
    internal static func stringToInt(string:String) -> Int{
    
        let nf = NSNumberFormatter()
        
        nf.numberStyle = .DecimalStyle
        
        let number = nf.numberFromString(string) ?? 0
        
        return number.integerValue
        
    }

}
